package com.hqyj.page.controller;

import com.hqyj.page.model.UserPage;
import com.hqyj.system.model.User;
import frame.controller.BaseController;
import frame.pageUtil.PagedResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/userPageController")
public class UserPageController extends BaseController {
//    @RequestMapping("/list.do")
//    public String List(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, UserPage userPage) {
//        //1.接收数据;
//        //3.调用业务;
//        List<UserPage> userPage_dbList = userPageService.queryAllUserPage();
//        for (UserPage userPage_db : userPage_dbList) {
//            System.out.println("--------userPageController------List()------"+userPage_db);
//        }
//        model.addAttribute("user_dbList",userPage_dbList);
//        //2.跳转页面;
//        return "view/page/userPageList";
//    }

    @RequestMapping("/listPage.do")
    public ModelAndView listPage(@RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                                 @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
        System.out.println("------------------传统---------------------");
        ModelAndView mv = new ModelAndView();
        // 当前页和每页的条数
        // 传入数据到分页工具类
        PagedResult<UserPage> pageResult = userPageService.getAllUserPageByPage(pageNumber, pageSize);
        // 数据传递到前台页面展示层
        mv.addObject("pageResult", pageResult);
        mv.setViewName("view/page/userPageList");
        return mv;
    }
}
